<?php
/**
 * Minhlog RSS订阅功能控制器
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * @category   Controller
 * @package    Frontend
 * @copyright  Copyright (c) 2009-2010 Minh.Shu@gmail.com
 * @license    New BSD License
 * @author     Minh.Shu
 * @version    $Id: FeedController.php 25 2010-02-16 11:11:45Z Minh.Shu $
 *
 */

class FeedController extends Minh_Controller_Action
{
    protected $_articleModel;

    public function init ()
    {
        if(null === $this->_articleModel){
            if(class_exists('Domain_Model_Article')){
                $this->_articleModel = new Domain_Model_Article();
            } else {
                throw new Exception('文章模型类不存在!');
            }
        }

        parent::init();
    }

    public function indexAction ()
    {
        $filter = new Zend_Filter_StripTags();
        $articleList = $this->_articleModel->getAllArticle();
        $entries = array();
        foreach ($articleList as $key => $article) {
            $entries[$key]['title'] = $article->article->articleTitle;
            $entries[$key]['link'] = 'http://' . $this->view->siteDomain . '/article/' . $article->article->articleId . '-1.html';
            $entries[$key]['description'] = trim($filter->filter($article->article->articleSummary));
            $entries[$key]['guid'] = (int) $article->article->articleId;
            $entries[$key]['lastUpdate'] = (int) $article->article->publishTime;
        }

        $rssArray = array('title' => $this->view->siteName , 'link' => 'http://' . $this->view->siteDomain . '/feed/' , 'description' => $this->seo['list']['index']['description'] , 'charset' => $this->view->encoding , 'entries' => $entries , 'author' => $this->view->author);
        $feed = Zend_Feed::importArray($rssArray, 'rss');
        $feed->send();
    }
}